<?php $this->Html->addCrumb('Invoices','/invoices'); ?>
<?php $this->Html->addCrumb('Overdue Invoices'); ?>
<div class="global-title">Overdue Invoices</div>
<p>&nbsp;</p>
	<a style="color:#000;font-weight:700;height:20px;padding:3px;" href="<?php echo Configure::read('base_url');?>invoices">Invoices Awaiting Payment</a>&nbsp;|&nbsp;
	<a style="background:#365EBA;color:#fff;font-weight:700; height:20px;padding:3px;" href="<?php echo Configure::read('base_url');?>invoices/overdue_invoices">Overdue Invoices</a>&nbsp;|&nbsp;
	<a style="color:#000; font-weight:700; height:20px;padding:3px;" href="<?php echo Configure::read('base_url');?>invoices/paid_invoices">Paid Invoices</a>
<?php echo $this->Form->create('Invoices', array('action' => 'overdue_invoices')); ?>
<br />Select Year: <select name="data[search_year]">
<?php 
	$reg_date=date("Y",strtotime($session->read('Auth.User.created')));
	$cur_date=date("Y");
	for($i=$reg_date;$i<=$cur_date;$i++){
	if($i==$cur_date)
		$selected=' selected="selected"';
	else
		$selected='';
?>
	<option <?php echo $selected;?> value="<?php echo $i;?>"><?php echo $i;?></option>
<?php } ?>
	</select>
<?php $months=array("01"=>"January","02"=>"February","03"=>"March","04"=>"April","05"=>"May","06"=>"June","07"=>"July","08"=>"August","09"=>"September","10"=>"Octomber","11"=>"November","12"=>"December");?>
Select Month: <select name="data[search_month]">
<?php
	foreach($months as $key=>$value){
	if($key==date('m'))
		$selected=' selected="selected"';
	else
		$selected='';
	echo'<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
	}
?>
</select>
<input type="submit" name="submit" value="Generate" class="button" />
</form>

<?php if(!empty($invoices)): ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="StateTable">
            <tr class="statetablerow">
			<th style="width:150px;">Reference # / Invoice ID</th>
			<th style="width:150px;">Invoice Date</th>
			<th style="width:150px;">Invoice Due Date</th>
			<th style="width:150px;">Total Sale Amount</th>
			<th style="width:150px;">Authentic Avenue Fees</th>
			<th style="width:174px;">Pay Now</th>
		</tr>	
	</table>
<ul class="accordinginv"  style="list-style-type: none;">
	<?php
        $i=0;
        foreach($invoices as $invoice):
             $invoice_date = $invoice['Invoice']['invoice_date'];
            $order_date_m1 = date("m", strtotime($invoice_date));
            $order_date_y1 = date("Y", strtotime($invoice_date));
            $order_date = date("Y-m-d H:i:s", mktime(0, 0, 0, $order_date_m1 - 1, 1, $order_date_y1));
            ?>
	<li>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="invoicetogle StateTable">
                <tr id="row_<?php echo $invoice['Invoice']['id']; ?>" class="invoicehead" style="cursor:pointer;">
		<td><?php echo $invoice['Invoice']['id'];?></td>
		<td><?php echo date("m-d-Y",strtotime($invoice['Invoice']['invoice_date']));?></td>
		<td><?php echo date("m-d-Y",strtotime($invoice['Invoice']['invoice_due_date']));?></td>
		<td>$<?php echo $invoice['Invoice']['total_sale'];?></td>
		<td>$<?php echo $invoice['Invoice']['aa_fee'];?></td>
		<td style="width:174px"><?php
			echo $this->Form->input("InvoiceId",array("type"=>"hidden","value"=>$invoice['Invoice']['id']));
			?>
			<input type="image" name="submit" value="Submit" src="<?php echo Configure::read('base_url');?>img/paypal.gif" />
			&nbsp;&nbsp;
			<?php
				echo $this->Form->create('Invoice', array('action' => 'process_invoice_gcheckout')); 
				echo $this->Form->input("id",array("type"=>"hidden","value"=>$invoice['Invoice']['id']));
			?>
			
			<input type="image" name="submit" value="gcheckout" src="<?php echo Configure::read('base_url');?>img/google_checkout.gif" />
			</form>
		</td>
	</tr>
       </table>
			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="invoicetogle StateTable">	
				<tr class="invoicehead" style="cursor:pointer;">
					<td style="text-align:left">Month :<?php echo date("m/d/Y",strtotime($order_date))." - ".date("m/d/Y",strtotime($invoice_date));?></td>
				</tr>
            </table>
            <ul style="list-style-type: none;<?php if($i==0){?>display:block;<?php }?>">
                <li>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="StateTable">
	<tr>
        <td class="nopad" colspan="6">
			<?php echo $this->requestAction("invoices/fetch_invoice_order/".$invoice['Invoice']['id'],array('return'));?>
		</td>
	</tr>    
	</table>
                </li>
            </ul>
    </li>
       <?php
      $i++;
       endforeach;?>
    </ul>
<?php else:?>
<br /><br />
<h2>No overdue invoices found.</h2>
<br /><br /><br />
<?php endif;?>
<div class="paging">
    <?php
		echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?> | 
	<?php echo $this->Paginator->numbers();?>
		| 
	<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
</div>

<script type="text/javascript">
jQuery('.invoicetogle').click(function(){
		var trackinv=jQuery('.invoicetogle').index(this);
		if(jQuery("ul.accordinginv li ul:eq("+trackinv+")").is(":hidden")) {
		jQuery("ul.accordinginv li ul:eq("+trackinv+")").show("slow");
		}
		else{
		jQuery("ul.accordinginv li ul:eq("+trackinv+")").hide("slow");
			}
		return false;
    });
</script>
<style type="text/css">
	table.CityTable, table.StateTable{text-align:center;width:100%;}
	table td{padding:5px;vertical-align: top;}
	table.StateTable th{background: #E6EEEE; padding: 5px; cursor:pointer;}
	table.CityTable th{padding: 5px; background: #C7DBF1;cursor:pointer; color:black;}
	table.StateTable td.nopad{padding:0;vertical-align: top;}
	tr.invoicehead{padding: 5px; background: #729FDC;color:black;font-weight:700;}
	tr.odd{background: #eee;}
	tr.headodd{padding: 5px; background: #C7DBF1;color:black;}
	tr.head1odd{padding: 5px; background: #E6EEEE;color:black;}
	td p span{color:#00B050;}
td.vendor h2 {font-size:20px; color: #00B050;}
</style>